/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.lzyzsd.circleprogress.utils.properties;

import com.github.lzyzsd.circleprogress.ResourceTable;
import com.github.lzyzsd.circleprogress.utils.properties.IInterface.AttributeObserver;
import com.github.lzyzsd.circleprogress.utils.properties.IInterface.ResourcePropertyHolder;
import com.github.lzyzsd.circleprogress.utils.properties.model.DountProgressModel;
import ohos.agp.components.AttrSet;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.global.resource.solidxml.TypedAttribute;

public class DountProgressResPropertyHolder extends ResourcePropertyHolder<DountProgressModel> {
    public DountProgressResPropertyHolder(Context context, AttrSet attrSet) {
        super(context,attrSet);
    }

    @Override
    public DountProgressModel obtainProperty() {
        model = new DountProgressModel(getContext());
        AttrHelper helper = new AttrHelper(getContext(), getAttrSet());
        helper.getTypeAttribute("finishedStrokeColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (result) -> model.setFinishedStrokeColor(result));
        helper.getTypeAttribute("unfinishedStrokeColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (result) -> model.setUnfinishedStrokeColor(result));
        helper.getTypeAttribute("showText", TypedAttribute.BOOLEAN_ATTR, (AttributeObserver<Boolean>) (result) -> model.setShowText(result));
        helper.getTypeAttribute("attributeResourceId", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) (result) -> model.setAttributeResourceId(result));
        helper.getTypeAttribute("finishedStrokeWidth", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) (result) -> model.setFinishedStrokeWidth( result));
        helper.getTypeAttribute("unfinishedStrokeWidth", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) (result) -> model.setUnfinishedStrokeWidth( result));
        helper.getTypeAttribute("textColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (result) -> model.setTextColor(result));
        helper.getTypeAttribute("textSize", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) (result) -> model.setTextSize( result));
        helper.getTypeAttribute("innerBottomTextSize", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) (result) -> model.setInnerBottomTextSize( result));
        helper.getTypeAttribute("innerBottomTextColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (result) -> model.setInnerBottomTextColor(result));
        helper.getTypeAttribute("innerBottomText", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) (result) -> model.setInnerBottomText(result));
        helper.getTypeAttribute("startingDegree", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) (result) -> model.setStartingDegree(result));
        helper.getTypeAttribute("innerBackgroundColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) (result) -> model.setInnerBackgroundColor(result));
        helper.getTypeAttribute("prefixText", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) (result) -> model.setPrefixText(result));
        helper.getTypeAttribute("suffixText", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) (result) -> model.setSuffixText(result));
        helper.getTypeAttribute("text", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) (result) -> model.setText(result));
        helper.getTypeAttribute("max", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) (result) -> model.setMax(result));
        helper.getTypeAttribute("progress", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) (result) -> model.setProgress(result));
        return model;
    }
}
